﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TT.Module.sysLogin;
using TT.ORM;
using System.Data;
using SQLHelper;

namespace Exp.BillDLL.dao
{
    public class daoClient
    {
        etyBaeSystemParamter basSysParam;

        public daoClient(etyBaeSystemParamter ibasSysParam)
        {
            basSysParam = ibasSysParam;
        }

        public bool Insert(etyCustomer eyTrk)
        {
            string sql = "insert into customer (PORT_CODE,CUSTOMER,CUST_NAME,CUST_TYPE,LG_NAME,FLOOR,HOURSE_NO,AREA,TEL_NO,PHONE_NO,BILL_FLAG,REMARK,LST_MOD,LST_USER,BILL_FROM,over_price_flag) "
                + "values(:PORT_CODE,:CUSTOMER,:CUST_NAME,:CUST_TYPE,:LG_NAME,:FLOOR,:HOURSE_NO,:AREA,:TEL_NO,:PHONE_NO,:BILL_FLAG,:REMARK,:LST_MOD,:LST_USER,:BILL_FROM,:over_price_flag)";

            return basSysParam.SqlHelp.ExecuteTrans(sql, eyTrk).Exec_Success;

        }

        public bool Update(etyCustomer eyTrk)
        {
            string sql = "update customer set cust_name=:cust_name,cust_type=:cust_type,lg_name=:lg_name,floor=:floor,hourse_no=:hourse_no,area=:area,tel_no=:tel_no,phone_no=:phone_no,bill_flag=:bill_flag,bill_from=:bill_from,remark=:remark,lst_mod=:lst_mod,lst_user=:lst_user,lst_upd_date=sysdate,over_price_flag=:over_price_flag"
                + " where port_code=:port_code and customer=:customer";

            return basSysParam.SqlHelp.ExecuteTrans(sql, eyTrk).Exec_Success;
        }

        public bool Delete(etyCustomer eyTrk)
        {
            string sql = "delete from bas_client "
                + " where port_code=:port_code and client_id=:client_id";

            return basSysParam.SqlHelp.ExecuteTrans(sql, eyTrk).Exec_Success;
        }

        public DataTable GetCustomer()
        {
            string sql = string.Empty;
            sql = "select CLIENT_ID,CLIENT_NO CUSTOMER,c.client_name CUST_NAME,sale_man,bill_flag,bill_group "
                + " from bas_client c "
                + " where port_code=:port_code ";

            DataTable dt;
            dt = basSysParam.SqlHelp.ExecuteReader(sql, new string[] { basSysParam.PORT_CODE });
            return dt;
        }
    }
}
